<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第二节：Flask-Restful插件 | Flask进阶课程课件</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../di-shi-er-zhang-ff1a-memcached-jiao-cheng.html" />
    
    
    <link rel="prev" href="../di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="14.2"
        data-chapter-title="第二节：Flask-Restful插件"
        data-filepath="di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.md"
        data-basepath=".."
        data-revision="Tue Aug 14 2018 17:50:50 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="chapter1.html">
            
                
                    <a href="../chapter1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        第一章：学前准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="chapter1/di-yi-jie-ff1a-xu-ni-huan-jing.html">
            
                
                    <a href="../chapter1/di-yi-jie-ff1a-xu-ni-huan-jing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第一节：虚拟环境
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="di-er-zhang-ff1a-ren-shi-web.html">
            
                
                    <a href="../di-er-zhang-ff1a-ren-shi-web.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        第二章：认识web
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        第三章：URL与视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-yi-jie-ff1a-di-yi-ge-flask-cheng-xu.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-yi-jie-ff1a-di-yi-ge-flask-cheng-xu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第一节：Flask简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-er-jie-ff1a-xiang-mu-pei-zhi.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-er-jie-ff1a-xiang-mu-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第二节：项目配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-san-jie-ff1a-url-yu-shi-tu-han-shu.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-san-jie-ff1a-url-yu-shi-tu-han-shu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        第三节：URL与视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-si-jie-ff1a-guan-yu-xiang-ying.html">
            
                
                    <a href="../di-san-zhang-ff1a-flask-ru-men-2014-2014-url/di-si-jie-ff1a-guan-yu-xiang-ying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        第四节：关于响应
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        第四章：模版
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-yi-jie-ff1a-mo-ban-jian-jie.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-yi-jie-ff1a-mo-ban-jian-jie.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第一节：模版简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-er-jie-ff1a-jinja2-mo-ban-gai-shu.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-er-jie-ff1a-jinja2-mo-ban-gai-shu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        第二节：Jinja2模版概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-san-jie-ff1a-jinja2-guo-lv-qi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-san-jie-ff1a-jinja2-guo-lv-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        第三节：过滤器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-si-jie-ff1a-jinja2-mo-ban-kong-zhi-yu-ju.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-si-jie-ff1a-jinja2-mo-ban-kong-zhi-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        第四节：控制语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-wu-jie-ff1a-jinja2-mo-ban-ce-shi-qi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-wu-jie-ff1a-jinja2-mo-ban-ce-shi-qi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        第五节：测试器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-liu-jie-ff1a-hong-he-import-yu-ju.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-liu-jie-ff1a-hong-he-import-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        第六节：宏和import语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-qijie-ff1a-include-he-set-yu-ju.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-qijie-ff1a-include-he-set-yu-ju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        第七节：include和set语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-ba-jie-ff1a-mo-ban-ji-cheng.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-ba-jie-ff1a-mo-ban-ji-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        第八节：模版继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-jiu-jie-ff1a-zhuan-yi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-jiu-jie-ff1a-zhuan-yi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        第九节：转义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-jie-ff1a-shu-ju-lei-xing-he-yun-suan-fu.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-jie-ff1a-shu-ju-lei-xing-he-yun-suan-fu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        第十节：数据类型和运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-yi-jie-ff1a-jing-tai-wen-jian-de-pei-zhi.html">
            
                
                    <a href="../di-si-zhang-ff1a-flask-ru-men-ff08-mo-ban-ff09/di-shi-yi-jie-ff1a-jing-tai-wen-jian-de-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        第十一节：静态文件的配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji.html">
            
                
                    <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        第五章：视图高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html">
            
                
                    <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji/di-yi-jie-ff1a-lei-shi-tu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第一节：类视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.html">
            
                
                    <a href="../di-wu-zhang-ff1a-shi-tu-gao-ji/di-er-jie-ff1a-lan-tu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第二节：蓝图和子域名
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第六章：SQLAlchemy数据库
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-mysql-shu-ju-ku-de-an-zhuang.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-mysql-shu-ju-ku-de-an-zhuang.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        第一节：MySQL数据库的安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-sqlalchemy-jie-shao-he-ji-ben-shi-yong.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-yi-jie-ff1a-sqlalchemy-jie-shao-he-ji-ben-shi-yong.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        第二节：SQLAlchemy介绍和基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-san-jie-ff1a-sqlalchemy-de-orm.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-san-jie-ff1a-sqlalchemy-de-orm.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        第三节：SQLAlchemy的ORM（1）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1a-sqlalchemy-de-orm-2.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1a-sqlalchemy-de-orm-2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        第四节：SQLAlchemy的ORM（2）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-wu-jie-ff1a-sqlalchemy-de-orm-3.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-wu-jie-ff1a-sqlalchemy-de-orm-3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        第五节：SQLAlchemy的ORM（3）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-liu-jie-ff1a-sqlalchemy-de-orm-4.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-liu-jie-ff1a-sqlalchemy-de-orm-4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        第六节：SQLAlchemy的ORM（4）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-qi-jie-ff1a-sqlalchemy-de-orm-5.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-qi-jie-ff1a-sqlalchemy-de-orm-5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        第七节：SQLAlchemy的ORM（5）
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1aflask-sqlalchemy.html">
            
                
                    <a href="../di-liu-zhang-ff1a-sqlalchemy-shu-ju-ku/di-si-jie-ff1aflask-sqlalchemy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        第八节：Flask-SQLAlchemy
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="di-qi-zhang-ff1a-flask-script.html">
            
                
                    <a href="../di-qi-zhang-ff1a-flask-script.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        第七章：Flask-Script
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="di-bazhang-ff1a-alembic-jiao-cheng.html">
            
                
                    <a href="../di-bazhang-ff1a-alembic-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        第八章：alembic教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="di-ba-zhang-ff1a-flask-migrate.html">
            
                
                    <a href="../di-ba-zhang-ff1a-flask-migrate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        第九章：Flask-Migrate
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10" data-path="di-jiu-zhang-ff1a-flask-wtf.html">
            
                
                    <a href="../di-jiu-zhang-ff1a-flask-wtf.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        第十章：Flask-WTF
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11" data-path="di-shi-yi-zhang-ff1a-cookie-he-session.html">
            
                
                    <a href="../di-shi-yi-zhang-ff1a-cookie-he-session.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        第十一章：cookie和session
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="di-shi-zhang-ff1a-shang-xia-wen.html">
            
                
                    <a href="../di-shi-zhang-ff1a-shang-xia-wen.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        第十二章：Flask上下文
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="13" data-path="di-shi-yi-zhang-ff1a-flask-xin-hao-ji-zhi.html">
            
                
                    <a href="../di-shi-yi-zhang-ff1a-flask-xin-hao-ji-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>13.</b>
                        
                        第十三章：Flask信号机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14" data-path="di-shi-si-zhang-ff1a-flask.html">
            
                
                    <a href="../di-shi-si-zhang-ff1a-flask.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.</b>
                        
                        第十四章：Flask-Restful
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.1" data-path="di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html">
            
                
                    <a href="../di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.1.</b>
                        
                        第一节：Restful API规范
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="14.2" data-path="di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html">
            
                
                    <a href="../di-shi-si-zhang-ff1a-flask/di-er-jie-ff1a-flask-restful-cha-jian.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.2.</b>
                        
                        第二节：Flask-Restful插件
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="15" data-path="di-shi-er-zhang-ff1a-memcached-jiao-cheng.html">
            
                
                    <a href="../di-shi-er-zhang-ff1a-memcached-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>15.</b>
                        
                        第十五章：memcached教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="16" data-path="di-shi-sizhang-ff1a-redis-jiao-cheng.html">
            
                
                    <a href="../di-shi-sizhang-ff1a-redis-jiao-cheng.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>16.</b>
                        
                        第十六章：redis教程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="17" data-path="di-shi-liu-zhang-ff1a-csrf-gong-ji.html">
            
                
                    <a href="../di-shi-liu-zhang-ff1a-csrf-gong-ji.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>17.</b>
                        
                        第十七章：CSRF攻击
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="18" data-path="di-shi-ba-zhang-ff1a-qi-niu-yun-pei-zhi.html">
            
                
                    <a href="../di-shi-ba-zhang-ff1a-qi-niu-yun-pei-zhi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>18.</b>
                        
                        第十八章：七牛云配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="19" data-path="di-shi-jiu-zhang-ff1a-bu-shu-flask-xiang-mu.html">
            
                
                    <a href="../di-shi-jiu-zhang-ff1a-bu-shu-flask-xiang-mu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>19.</b>
                        
                        第十九章：部署Flask项目
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >Flask进阶课程课件</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="flaskrestful&#x63D2;&#x4EF6;">Flask-Restful&#x63D2;&#x4EF6;</h1>
<h3 id="&#x4ECB;&#x7ECD;&#xFF1A;">&#x4ECB;&#x7ECD;&#xFF1A;</h3>
<p><code>Flask-Restful</code>&#x662F;&#x4E00;&#x4E2A;&#x4E13;&#x95E8;&#x7528;&#x6765;&#x5199;<code>restful api</code>&#x7684;&#x4E00;&#x4E2A;&#x63D2;&#x4EF6;&#x3002;&#x4F7F;&#x7528;&#x4ED6;&#x53EF;&#x4EE5;&#x5FEB;&#x901F;&#x7684;&#x96C6;&#x6210;<code>restful api</code>&#x529F;&#x80FD;&#x3002;&#x5728;<code>app</code>&#x7684;&#x540E;&#x53F0;&#x4EE5;&#x53CA;&#x7EAF;<code>api</code>&#x7684;&#x540E;&#x53F0;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E2A;&#x63D2;&#x4EF6;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x8282;&#x7701;&#x5F88;&#x591A;&#x65F6;&#x95F4;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x666E;&#x901A;&#x7684;&#x7F51;&#x7AD9;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E2A;&#x63D2;&#x4EF6;&#x5C31;&#x663E;&#x5F97;&#x6709;&#x4E9B;&#x9E21;&#x808B;&#x4E86;&#xFF0C;&#x56E0;&#x4E3A;&#x5728;&#x666E;&#x901A;&#x7684;&#x7F51;&#x9875;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x662F;&#x9700;&#x8981;&#x53BB;&#x6E32;&#x67D3;HTML&#x4EE3;&#x7801;&#x7684;&#xFF0C;&#x800C;<code>Flask-Restful</code>&#x5728;&#x6BCF;&#x4E2A;&#x8BF7;&#x6C42;&#x4E2D;&#x90FD;&#x662F;&#x8FD4;&#x56DE;<code>json</code>&#x683C;&#x5F0F;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<h3 id="&#x5B89;&#x88C5;&#xFF1A;">&#x5B89;&#x88C5;&#xFF1A;</h3>
<p><code>Flask-Restful</code>&#x9700;&#x8981;&#x5728;<code>Flask 0.8</code>&#x4EE5;&#x4E0A;&#x7684;&#x7248;&#x672C;&#xFF0C;&#x5728;<code>Python2.6</code>&#x6216;&#x8005;<code>Python3.3</code>&#x4E0A;&#x8FD0;&#x884C;&#x3002;&#x901A;&#x8FC7;<code>pip install flask-restful</code>&#x5373;&#x53EF;&#x5B89;&#x88C5;&#x3002;</p>
<h3 id="&#x5B9A;&#x4E49;restful&#x7684;&#x89C6;&#x56FE;&#xFF1A;">&#x5B9A;&#x4E49;Restful&#x7684;&#x89C6;&#x56FE;&#xFF1A;</h3>
<p>&#x5982;&#x679C;&#x4F7F;&#x7528;<code>Flask-Restful</code>&#xFF0C;&#x90A3;&#x4E48;&#x5B9A;&#x4E49;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5C31;&#x8981;&#x7EE7;&#x627F;&#x81EA;<code>flask_restful.Resource</code>&#x7C7B;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x6839;&#x636E;&#x5F53;&#x524D;&#x8BF7;&#x6C42;&#x7684;<code>method</code>&#x6765;&#x5B9A;&#x4E49;&#x76F8;&#x5E94;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x6BD4;&#x5982;&#x671F;&#x671B;&#x5BA2;&#x6237;&#x7AEF;&#x662F;&#x4F7F;&#x7528;<code>get</code>&#x65B9;&#x6CD5;&#x53D1;&#x9001;&#x8FC7;&#x6765;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;<code>get</code>&#x65B9;&#x6CD5;&#x3002;&#x7C7B;&#x4F3C;&#x4E8E;<code>MethodView</code>&#x3002;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> flask <span class="hljs-keyword">import</span> Flask,render_template,url_for
<span class="hljs-keyword">from</span> flask_restful <span class="hljs-keyword">import</span> Api,Resource

app = Flask(__name__)
<span class="hljs-comment"># &#x7528;Api&#x6765;&#x7ED1;&#x5B9A;app</span>
api = Api(app)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">IndexView</span><span class="hljs-params">(Resource)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;username&quot;</span>:<span class="hljs-string">&quot;zhiliao&quot;</span>}

api.add_resource(IndexView,<span class="hljs-string">&apos;/&apos;</span>,endpoint=<span class="hljs-string">&apos;index&apos;</span>)
</code></pre>
<p>&#x6CE8;&#x610F;&#x4E8B;&#x9879;&#xFF1A;  </p>
<ol>
<li><code>endpoint</code>&#x662F;&#x7528;&#x6765;&#x7ED9;<code>url_for</code>&#x53CD;&#x8F6C;<code>url</code>&#x7684;&#x65F6;&#x5019;&#x6307;&#x5B9A;&#x7684;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x5199;<code>endpoint</code>&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x4F1A;&#x4F7F;&#x7528;&#x89C6;&#x56FE;&#x7684;&#x540D;&#x5B57;&#x7684;&#x5C0F;&#x5199;&#x6765;&#x4F5C;&#x4E3A;<code>endpoint</code>&#x3002;  </li>
<li><code>add_resource</code>&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8BBF;&#x95EE;&#x8FD9;&#x4E2A;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x7684;<code>url</code>&#xFF0C;&#x8FD9;&#x4E2A;<code>url</code>&#x53EF;&#x4EE5;&#x8DDF;&#x4E4B;&#x524D;&#x7684;<code>route</code>&#x4E00;&#x6837;&#xFF0C;&#x53EF;&#x4EE5;&#x4F20;&#x9012;&#x53C2;&#x6570;&#x3002;&#x5E76;&#x4E14;&#x8FD8;&#x6709;&#x4E00;&#x70B9;&#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x4F20;&#x9012;&#x591A;&#x4E2A;<code>url</code>&#x6765;&#x6307;&#x5B9A;&#x8FD9;&#x4E2A;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x3002;</li>
</ol>
<h3 id="&#x53C2;&#x6570;&#x89E3;&#x6790;&#xFF1A;">&#x53C2;&#x6570;&#x89E3;&#x6790;&#xFF1A;</h3>
<p><code>Flask-Restful</code>&#x63D2;&#x4EF6;&#x63D0;&#x4F9B;&#x4E86;&#x7C7B;&#x4F3C;<code>WTForms</code>&#x6765;&#x9A8C;&#x8BC1;&#x63D0;&#x4EA4;&#x7684;&#x6570;&#x636E;&#x662F;&#x5426;&#x5408;&#x6CD5;&#x7684;&#x5305;&#xFF0C;&#x53EB;&#x505A;<code>reqparse</code>&#x3002;&#x4EE5;&#x4E0B;&#x662F;&#x57FA;&#x672C;&#x7528;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-python">parser = reqparse.RequestParser()
parser.add_argument(<span class="hljs-string">&apos;username&apos;</span>,type=str,help=<span class="hljs-string">&apos;&#x8BF7;&#x8F93;&#x5165;&#x7528;&#x6237;&#x540D;&apos;</span>)
args = parser.parse_args()
</code></pre>
<p><code>add_argument</code>&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x8FD9;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x8FD9;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7B49;&#x3002;&#x4EE5;&#x4E0B;&#x5C06;&#x5BF9;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x4E00;&#x4E9B;&#x53C2;&#x6570;&#x505A;&#x8BE6;&#x7EC6;&#x8BB2;&#x89E3;&#xFF1A;  </p>
<ol>
<li><code>default</code>&#xFF1A;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x6CA1;&#x6709;&#x503C;&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x7684;&#x503C;&#x3002;  </li>
<li><code>required</code>&#xFF1A;&#x662F;&#x5426;&#x5FC5;&#x987B;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;False&#xFF0C;&#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E3A;<code>True</code>&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x5C31;&#x5FC5;&#x987B;&#x63D0;&#x4EA4;&#x4E0A;&#x6765;&#x3002;  </li>
<li><code>type</code>&#xFF1A;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x5982;&#x679C;&#x6307;&#x5B9A;&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x4F7F;&#x7528;&#x6307;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x6765;&#x5F3A;&#x5236;&#x8F6C;&#x6362;&#x63D0;&#x4EA4;&#x4E0A;&#x6765;&#x7684;&#x503C;&#x3002;  </li>
<li><code>choices</code>&#xFF1A;&#x9009;&#x9879;&#x3002;&#x63D0;&#x4EA4;&#x4E0A;&#x6765;&#x7684;&#x503C;&#x53EA;&#x6709;&#x6EE1;&#x8DB3;&#x8FD9;&#x4E2A;&#x9009;&#x9879;&#x4E2D;&#x7684;&#x503C;&#x624D;&#x7B26;&#x5408;&#x9A8C;&#x8BC1;&#x901A;&#x8FC7;&#xFF0C;&#x5426;&#x5219;&#x9A8C;&#x8BC1;&#x4E0D;&#x901A;&#x8FC7;&#x3002;  </li>
<li><code>help</code>&#xFF1A;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;&#x5982;&#x679C;&#x9A8C;&#x8BC1;&#x5931;&#x8D25;&#x540E;&#xFF0C;&#x5C06;&#x4F1A;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x7684;&#x503C;&#x4F5C;&#x4E3A;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;  </li>
<li><code>trim</code>&#xFF1A;&#x662F;&#x5426;&#x8981;&#x53BB;&#x6389;&#x524D;&#x540E;&#x7684;&#x7A7A;&#x683C;&#x3002;</li>
</ol>
<p>&#x5176;&#x4E2D;&#x7684;<code>type</code>&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>python</code>&#x81EA;&#x5E26;&#x7684;&#x4E00;&#x4E9B;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>flask_restful.inputs</code>&#x4E0B;&#x7684;&#x4E00;&#x4E9B;&#x7279;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x6765;&#x5F3A;&#x5236;&#x8F6C;&#x6362;&#x3002;&#x6BD4;&#x5982;&#x4E00;&#x4E9B;&#x5E38;&#x7528;&#x7684;&#xFF1A;  </p>
<ol>
<li><code>url</code>&#xFF1A;&#x4F1A;&#x5224;&#x65AD;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x503C;&#x662F;&#x5426;&#x662F;&#x4E00;&#x4E2A;url&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x662F;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;  </li>
<li><code>regex</code>&#xFF1A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x3002;  </li>
<li><code>date</code>&#xFF1A;&#x5C06;&#x8FD9;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x6362;&#x4E3A;<code>datetime.date</code>&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;&#x5982;&#x679C;&#x8F6C;&#x6362;&#x4E0D;&#x6210;&#x529F;&#xFF0C;&#x5219;&#x4F1A;&#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x5F02;&#x5E38;&#x3002;</li>
</ol>
<h3 id="&#x8F93;&#x51FA;&#x5B57;&#x6BB5;&#xFF1A;">&#x8F93;&#x51FA;&#x5B57;&#x6BB5;&#xFF1A;</h3>
<p>&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x597D;&#x4E00;&#x4E9B;&#x5B57;&#x6BB5;&#x7528;&#x4E8E;&#x8FD4;&#x56DE;&#x3002;&#x4EE5;&#x540E;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;ORM&#x6A21;&#x578B;&#x6216;&#x8005;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x6A21;&#x578B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4ED6;&#x4F1A;&#x81EA;&#x52A8;&#x7684;&#x83B7;&#x53D6;&#x6A21;&#x578B;&#x4E2D;&#x7684;&#x76F8;&#x5E94;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x751F;&#x6210;<code>json</code>&#x6570;&#x636E;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x3002;&#x8FD9;&#x5176;&#x4E2D;&#x9700;&#x8981;&#x5BFC;&#x5165;<code>flask_restful.marshal_with</code>&#x88C5;&#x9970;&#x5668;&#x3002;&#x5E76;&#x4E14;&#x9700;&#x8981;&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x5178;&#xFF0C;&#x6765;&#x6307;&#x793A;&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x4EE5;&#x53CA;&#x8BE5;&#x5B57;&#x6BB5;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x3002;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ProfileView</span><span class="hljs-params">(Resource)</span>:</span>
    resource_fields = {
        <span class="hljs-string">&apos;username&apos;</span>: fields.String,
        <span class="hljs-string">&apos;age&apos;</span>: fields.Integer,
        <span class="hljs-string">&apos;school&apos;</span>: fields.String
    }

<span class="hljs-decorator">    @marshal_with(resource_fields)</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get</span><span class="hljs-params">(self,user_id)</span>:</span>
        user = User.query.get(user_id)
        <span class="hljs-keyword">return</span> user
</code></pre>
<p>&#x5728;<code>get</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x8FD4;&#x56DE;<code>user</code>&#x7684;&#x65F6;&#x5019;&#xFF0C;<code>flask_restful</code>&#x4F1A;&#x81EA;&#x52A8;&#x7684;&#x8BFB;&#x53D6;<code>user</code>&#x6A21;&#x578B;&#x4E0A;&#x7684;<code>username</code>&#x4EE5;&#x53CA;<code>age</code>&#x8FD8;&#x6709;<code>school</code>&#x5C5E;&#x6027;&#x3002;&#x7EC4;&#x88C5;&#x6210;&#x4E00;&#x4E2A;<code>json</code>&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x3002;</p>
<h4 id="&#x91CD;&#x547D;&#x540D;&#x5C5E;&#x6027;&#xFF1A;">&#x91CD;&#x547D;&#x540D;&#x5C5E;&#x6027;&#xFF1A;</h4>
<p>&#x5F88;&#x591A;&#x65F6;&#x5019;&#x4F60;&#x9762;&#x5411;&#x516C;&#x4F17;&#x7684;&#x5B57;&#x6BB5;&#x540D;&#x79F0;&#x662F;&#x4E0D;&#x540C;&#x4E8E;&#x5185;&#x90E8;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x3002;&#x4F7F;&#x7528; attribute&#x53EF;&#x4EE5;&#x914D;&#x7F6E;&#x8FD9;&#x79CD;&#x6620;&#x5C04;&#x3002;&#x6BD4;&#x5982;&#x73B0;&#x5728;&#x60F3;&#x8981;&#x8FD4;&#x56DE;<code>user.school</code>&#x4E2D;&#x7684;&#x503C;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x8FD4;&#x56DE;&#x7ED9;&#x5916;&#x9762;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x60F3;&#x4EE5;<code>education</code>&#x8FD4;&#x56DE;&#x56DE;&#x53BB;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x8FD9;&#x6837;&#x5199;&#xFF1A;</p>
<pre><code class="lang-python">resource_fields = {
    <span class="hljs-string">&apos;education&apos;</span>: fields.String(attribute=<span class="hljs-string">&apos;school&apos;</span>)
}
</code></pre>
<h4 id="&#x9ED8;&#x8BA4;&#x503C;&#xFF1A;">&#x9ED8;&#x8BA4;&#x503C;&#xFF1A;</h4>
<p>&#x5728;&#x8FD4;&#x56DE;&#x4E00;&#x4E9B;&#x5B57;&#x6BB5;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6709;&#x65F6;&#x5019;&#x53EF;&#x80FD;&#x6CA1;&#x6709;&#x503C;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x5728;&#x6307;&#x5B9A;<code>fields</code>&#x7684;&#x65F6;&#x5019;&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-python">resource_fields = {
    <span class="hljs-string">&apos;age&apos;</span>: fields.Integer(default=<span class="hljs-number">18</span>)
}
</code></pre>
<h4 id="&#x590D;&#x6742;&#x7ED3;&#x6784;&#xFF1A;">&#x590D;&#x6742;&#x7ED3;&#x6784;&#xFF1A;</h4>
<p>&#x6709;&#x65F6;&#x5019;&#x60F3;&#x8981;&#x5728;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x683C;&#x5F0F;&#x4E2D;&#xFF0C;&#x5F62;&#x6210;&#x6BD4;&#x8F83;&#x590D;&#x6742;&#x7684;&#x7ED3;&#x6784;&#x3002;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E00;&#x4E9B;&#x7279;&#x6B8A;&#x7684;&#x5B57;&#x6BB5;&#x6765;&#x5B9E;&#x73B0;&#x3002;&#x6BD4;&#x5982;&#x8981;&#x5728;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x4E2D;&#x653E;&#x7F6E;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>fields.List</code>&#xFF0C;&#x6BD4;&#x5982;&#x5728;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x4E0B;&#x9762;&#x53C8;&#x662F;&#x4E00;&#x4E2A;&#x5B57;&#x5178;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>fields.Nested</code>&#x3002;&#x4EE5;&#x4E0B;&#x5C06;&#x8BB2;&#x89E3;&#x4E0B;&#x590D;&#x6742;&#x7ED3;&#x6784;&#x7684;&#x7528;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ProfileView</span><span class="hljs-params">(Resource)</span>:</span>
    resource_fields = {
        <span class="hljs-string">&apos;username&apos;</span>: fields.String,
        <span class="hljs-string">&apos;age&apos;</span>: fields.Integer,
        <span class="hljs-string">&apos;school&apos;</span>: fields.String,
        <span class="hljs-string">&apos;tags&apos;</span>: fields.List(fields.String),
        <span class="hljs-string">&apos;more&apos;</span>: fields.Nested({
            <span class="hljs-string">&apos;signature&apos;</span>: fields.String
        })
    }
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../di-shi-si-zhang-ff1a-flask/di-yi-jie-ff1a-restful-api-gui-fan.html" class="navigation navigation-prev " aria-label="Previous page: 第一节：Restful API规范"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../di-shi-er-zhang-ff1a-memcached-jiao-cheng.html" class="navigation navigation-next " aria-label="Next page: 第十五章：memcached教程"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
